package command;

import java.util.HashMap;
import java.util.Map;
import command_impl.*;

public class SystemCommandFactory extends CommandFactory {

	protected static Map<CommandCode, Class<? extends Command>> commandMap = new HashMap<>();
	static{
		commandMap.put(CommandCode.EXIT,ExitCommand.class);
		commandMap.put(CommandCode.SIGNUP,SignupCommand.class);
		commandMap.put(CommandCode.LOGIN,LoginCommand.class);
		commandMap.put(CommandCode.HELP,HelpCommand.class);
		commandMap.put(CommandCode.LIST,ListCommand.class);
		commandMap.put(CommandCode.ESTABLISH, EstablishCommand.class);
	}
	
	@Override
	public Command buildCommand(CommandCode cmd) {
		
		if(!commandMap.containsKey(cmd)){
			System.out.println("您尚未登录，暂时无法使用此功能");
			return null;
		}
		Class<? extends Command> cmdClass = commandMap.get(cmd);
		
		if(cmdClass!=null){
			try {
				return cmdClass.newInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		return null;
	}

}
